﻿using System;
using DiveDeeper.VsxLibrary.Core;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;

namespace DiveDeeper.HowToPackage
{
  [CommandID(GuidList.GuidHowToPackageCmdSetString, PkgCmdIDList.cmdShowLearnVSXNowTool)]
  internal sealed class LearnVSXNowViewCommandHandler : MenuCommandHandler
  {
    #region Lifecycle methods

    // ------------------------------------------------------------------------------
    /// <summary>
    /// Initializes a new instance of menu command handler.
    /// </summary>
    /// <param name="package">Package owning the command handler.</param>
    // ------------------------------------------------------------------------------
    public LearnVSXNowViewCommandHandler(Package package)
      : base(package)
    {
    }

    #endregion

    #region Overridden methods

    // ------------------------------------------------------------------------------
    /// <summary>
    /// Override this method to define how the command should be executed.
    /// </summary>
    /// <param name="command">OleMenuCommand instance</param>
    // ------------------------------------------------------------------------------
    protected override void OnExecute(OleMenuCommand command)
    {
      ToolWindowPane window = 
        Package.FindToolWindow(typeof(LearnVSXNowToolWindow), 0, true);
      if ((null == window) || (null == window.Frame))
      {
        throw new NotSupportedException(Resources.CanNotCreateWindow);
      }
      IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
      Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
    }

    #endregion
  }
}

